package com.low.service.impl;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.low.entity.Psysacount;
import com.low.entity.PsysacountExample;
import com.low.mapper.PsysacountMapper;
import com.low.service.IPsysacount;



@Service
public class PsysacountImpl  implements IPsysacount{

	@Resource
	PsysacountMapper sysacountMapper;
	/**
	 * 新增登录账户
	 */
	public void addSysacount(Psysacount sysacount) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Calendar cal = Calendar.getInstance();
		Timestamp timestamp = Timestamp.valueOf(format.format(cal.getTime()));
		sysacount.setpRegtime(timestamp);
		if(sysacount.getpAuthstatus()==null || "".equals(sysacount.getpAuthstatus())){
			sysacount.setpAuthstatus("未授权");
		}
		sysacountMapper.insert(sysacount);
	}
	

	/**
	 *查询所有用户 
	 */
	@Override
	public List<Psysacount> findSysacount() {
		PsysacountExample sysacountExample = new PsysacountExample();
		sysacountExample.setDistinct(true);
		sysacountExample.setOrderByClause("P_AcountName");
		return sysacountMapper.selectByExample(sysacountExample);
	}
	/**
	 * 管理员修改账户权限
	 */
	@Override
	public void updSysacount(Psysacount sysacount) {
		sysacountMapper.updateByPrimaryKeySelective(sysacount);
	}
	/**
	 * 根据账户名删除账户
	 * @param acountname
	 */
	@Override
	public void removeSysacount(String acountname) {
		sysacountMapper.deleteByPrimaryKey(acountname);
	}
	/**
	 * 根据账户名查询一条数据
	 */
	@Override
	public Psysacount findByAcountname(String acountname) {
		
		return sysacountMapper.selectByPrimaryKey(acountname);
	}
	/**
	 * 根据权限组查询账户
	 */
	@Override
	public List<Psysacount> findByPermission(Integer groupid) {
		
		return sysacountMapper.selectByPermission(groupid);
	}
	@Override
	public Psysacount selectByIdnur(String idnur) {
		// TODO Auto-generated method stub
		return sysacountMapper.selectByIdnur(idnur);
	}


	@Override
	public Psysacount findSysaccountByNameAndPass(String username,
			String password) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}


	@Override
	public Psysacount findloginrecordByNameAndPass(String username,
			String password) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
